
<?php

class Bootstrap{


	public function __construct($aplicacao){
		self::erros();
		self::includes();
		self::carregamento();
		self::iniConfig($aplicacao);
		self::layout();
		self::controlador();
	}




	public function iniConfig($aplicacao){
		defined('APPLICATION_PATH')	|| define('APPLICATION_PATH',	realpath(dirname(__FILE__) . '/../application'));

		$arquivoConfig = "../application/configs/application.ini";
		$config = new Zend_Config_Ini($arquivoConfig , $aplicacao);
		Zend_Registry::set('config',$config);
		$db = Zend_Db::factory($config->resources->db, $config);
		$db->setFetchMode(Zend_Db::FETCH_OBJ);
		Zend_Registry::set('db', $db);
		Zend_Db_Table::setDefaultAdapter($db);
	}


	public function layout(){
		Zend_Layout::startMvc(
              array(
                  'layoutPath' => '../application/modules/site/layouts',
                  'layout' => 'layout'
              )
      );

	}

	public function erros(){
	error_reporting(E_ALL | E_STRICT);
	ini_set('display_errors','on');
	date_default_timezone_set('America/Sao_Paulo');
	}

	public function includes(){
	set_include_path(
	PATH_SEPARATOR . '../library'.
    PATH_SEPARATOR . '../library/Twitter'
	.PATH_SEPARATOR . '../library/Raxiv'
	.PATH_SEPARATOR . '../library/Raxiv/Action'
 	. PATH_SEPARATOR . get_include_path());
	}

	public function carregamento(){
		require_once 'Zend/Loader/Autoloader.php';
		Zend_Loader_Autoloader::autoload("Application");
		$loader = Zend_Loader_Autoloader::getInstance();
		$loader->registerNamespace("Raxiv");
        $loader->registerNamespace("Twitter");
		$loader->registerNamespace("Admin_");
		$loader->registerNamespace("Site_");

		Zend_Controller_Action_HelperBroker::addPath( 'public/admin/Raxiv/Action/');
		Zend_Controller_Action_HelperBroker::addPrefix('Raxiv_Action');
		Zend_Session::start();
		$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
		$viewRenderer->initView();
		$viewRenderer->view->addHelperPath('Raxiv/View/Helper', 'Raxiv_View_Helper');
	}



	public function controlador(){
		$front = Zend_Controller_Front::getInstance();
	//	$front->registerPlugin(new Raxiv_Plugin_Autenticacao(),1);
		$front->registerPlugin(new Raxiv_Plugin_Layout(),1);
		self::inicializaModulos();
		$front->throwExceptions(true);
		$front->setBaseUrl();
		$front->dispatch();

	}

	protected function inicializaModulos( ){
		$front = Zend_Controller_Front::getInstance();
		$front->addControllerDirectory("../application/modules/admin/controllers",'admin');
		$front->addModuleDirectory('../application/modules/admin/controllers','admin');
	}

}